﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AMS.DeDuplicator.CommonLayer;
using AMS.DeDuplicator.CommonLayer.Adapter;
using AMS.DeDuplicator.BusinessLayer.Command;

namespace AMS.DeDuplicator.ApplicationLayer.State
{
    class DeleteAllDuplicatesCommand : Command
    {
        DeleteReplaceFacade _deleteCommand;
        TreeViewAdapter _tv;

        public DeleteAllDuplicatesCommand(TreeViewAdapter tv)
        {
            InputValidator.ValidateNotNull(tv);
            _tv = tv;
        }

        public override bool Execute()
        {
            // almost no code duplication afterall!
            _deleteCommand = new DeleteReplaceFacade(_tv.GetNonRootIterator());
            if (_deleteCommand.Execute())
            {
                this.Executed = true;
                return true;
            }

            return false;
        }

        public override bool Undo()
        {
            // going to have problems with multiple Undo...
            if (_deleteCommand == null)
                return false;

            _deleteCommand.Undo();
            this.Executed = false;
            return true;
        }
    }
}
